﻿-- =============================================
-- Description	: Drop all constraints
-- See			: http://www.codeguru.com/forum/archive/index.php/t-247330.html
-- =============================================

declare @sql varchar(1024)
declare curs cursor for
select 'ALTER TABLE '+tab.name+' DROP CONSTRAINT '+cons.name
from sys.objects cons,sys.objects tab
where cons.type in ('C', 'F', 'PK', 'UQ', 'D')
and cons.parent_object_id=tab.object_id and tab.type='U'
order by cons.type

open curs
fetch next from curs into @sql
while (@@fetch_status = 0)
begin
exec(@sql)
fetch next from curs into @sql
end
close curs
deallocate curs



-- =============================================
-- Description	: Drop all table from database
-- See			: http://www.holisticsystems.co.uk/blog/?p=3
-- =============================================

DECLARE tables_cursor CURSOR
FOR SELECT name FROM sysobjects WHERE type = 'U'

OPEN tables_cursor
DECLARE @tablename sysname
FETCH NEXT FROM tables_cursor INTO @tablename
WHILE (@@FETCH_STATUS <> -1)
BEGIN
EXEC ('DROP TABLE ' + @tablename)
FETCH NEXT FROM tables_cursor INTO @tablename
END
DEALLOCATE tables_cursor





 -- =============================================
-- Description	: Delete only Data from tables.
-- =============================================
   /*
	
	truncate table Users;
	truncate table Staffs;	
	
	truncate table ItemCategories;
	truncate table ItemBrands;
	truncate table Inventories;
	truncate table InventoryQtyIO;
	truncate table ItemSuppliers;	
	
	truncate table SaleOrders;
	truncate table SaleOrderItems;
	truncate table InventoryQtyIO;
	
	truncate table Payments;
*/